package com.example.huwang.utils;

import android.content.res.AssetManager;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.example.huwang.model.CaseBean;
import com.example.huwang.model.DefinitionBean;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;

/**
 * Created by 张柱 on 2022/4/12
 */
public class AppConfig {
    /**
     * 网购诈骗
     * 游戏诈骗
     * 盗号诈骗
     * 刷单诈骗
     * 虚假中奖
     * 校园贷
     */
    public static final int TYPE_WLZP = 1;
    public static final int TYPE_YXZP = 2;
    public static final int TYPE_DHZP = 3;
    public static final int TYPE_SDZP = 4;
    public static final int TYPE_XJZJ = 5;
    public static final int TYPE_XYD = 6;

    private static List<CaseBean> sContentConfig;
    private static List<DefinitionBean> sDefinitionConfig;
    public static String[] dangerPhoneArr = new String[]{"15298887819", "19965417819"}; //风险电话 本地写死
    public static String smsDangerStr = "兼职刷单充值返利直播打赏游戏皮肤卖号校园贷汇钱救急";


    /**
     * 获取诈骗类型列表
     * @return
     */
    public static List<DefinitionBean> getDefinitionConfig() {
        if (sDefinitionConfig == null) {
            String content = parseFile("definition_config.json");
            sDefinitionConfig = JSON.parseObject(content, new TypeReference<List<DefinitionBean>>() {
            });
        }

        return sDefinitionConfig;
    }

    /**
     * 获取案例列表
     * @return
     */
    public static List<CaseBean> getContentConfig() {
        if (sContentConfig == null) {
            String content = parseFile("content_config.json");
            sContentConfig = JSON.parseObject(content, new TypeReference<List<CaseBean>>() {
            });
        }
        return sContentConfig;
    }


    private static String parseFile(String fileName) {
        AssetManager assets = AppGlobals.getApplication().getAssets();
        InputStream is = null;
        BufferedReader br = null;
        StringBuilder builder = new StringBuilder();
        try {
            is = assets.open(fileName);
            br = new BufferedReader(new InputStreamReader(is));
            String line = null;
            while ((line = br.readLine()) != null) {
                builder.append(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (is != null) {
                    is.close();
                }
                if (br != null) {
                    br.close();
                }
            } catch (Exception e) {

            }
        }

        return builder.toString();
    }

}
